/******************** (C) COPYRIGHT 2007 STMicroelectronics ********************
* File Name          : spi_flash.h
* Author             : MCD Application Team
* Date First Issued  : 02/05/2007
* Description        : Header for spi_flash.c file.
********************************************************************************
* History:
* 05/21/2007: V0.3
* 04/02/2007: V0.2
* 02/05/2007: V0.1
********************************************************************************
* THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
* CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __SPI_FLASH_H
#define __SPI_FLASH_H
/* Includes ------------------------------------------------------------------*/
#include "stm32f10x_lib.h"
#define FlashBusyFlag	0x5A

#define OTA_SUBSECTOR           (30*16)		// 32 - 30 = 02 Sector
#define FLASH_OTA_ADDR          (u32)(OTA_SUBSECTOR<<12)
#define FLASH_END_OTA_ADDR      (u32)(END_OTA_SUBSECTOR<<12)

#define  FLASH_DownloadAddress  FLASH_OTA_ADDR


#define SPI_FLASH_PAGESIZE  	256
#define M25P64_ID			(u32)0x00208015
#define AT25DF641_ID		(u32)0x001F4800
#define A25L016PUM_ID		(u32)0x007F3720
#define FLASHTYPE_ID		M25P64_ID

/* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
/* Exported macro ------------------------------------------------------------*/
/* Select SPI FLASH: ChipSelect pin low  */
#define SPI_FLASH_CS_LOW()     GPIO_ResetBits(GPIOA, GPIO_Pin_4)
/* Deselect SPI FLASH: ChipSelect pin high */
#define SPI_FLASH_CS_HIGH()    GPIO_SetBits(GPIOA, GPIO_Pin_4)

/* Exported functions ------------------------------------------------------- */
/*----- High layer function -----*/

void SPI_FLASH_SubSectorErase(u32 SectorAddr);
void SPI_FLASH_SectorErase(u32 SectorAddr);
void SPI_FLASH_BulkErase(void);
void SPI_FLASH_PageWrite(u8* pBuffer, u32 WriteAddr, u16 NumByteToWrite);
void SPI_FLASH_BufferWrite(u8* pBuffer, u32 WriteAddr, u16 NumByteToWrite);
void SPI_FLASH_BufferRead(u8* pBuffer, u32 ReadAddr, u16 NumByteToRead);
void BlockEraseSubSFlash(u32 StartAddr , u32 EndAddr);
void SPI_FLASH_EndReadSequence(void);
void SPI_FLASH_DeepPowerDown(void);
void SPI_FLASH_WakeUP(void);

/*-----   Read  function   -----*/
void SPI_FLASH_StartReadSequence(u32 ReadAddr);
u8 SPI_FLASH_ReadByteSequence(void);
u32 SPI_FLASH_ReadID(void);
u8 SPI_FLASH_ReadByte(u32 ReadAddr);

/*-----   Write  function   -----*/
void SPI_FLASH_WriteByte(u8 WriteByte , u32 WriteAddr );
void SPI_FLASH_PageWrite(u8* pBuffer, u32 WriteAddr, u16 NumByteToWrite);
void SPI_FLASH_StartWriteSequence(u32 WriteAddr);

/*----- Low layer function -----*/
u8 SPI_FLASH_SendByte(u8 byte);
u16 SPI_FLASH_SendHalfWord(u16 HalfWord);
void SPI_FLASH_WriteEnable(void);
void SPI_FLASH_WaitForWriteEnd(void);
void SPI_FLASH_DisadbleProtection(void);

extern u8 FlashBusy;

#endif /* __SPI_FLASH_H */

/******************* (C) COPYRIGHT 2007 STMicroelectronics *****END OF FILE****/
